/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include <locale.h>
#include <stdlib.h>
#include <wctype.h>
#include <info/device_api_version.h>
#include "functionalext.h"

const int COUNT = 136104;
const int SIZE = 1114111;  // unicode max: 10FFFF

/**
 * @tc.name      : iswalpha_l_0100
 * @tc.desc      : Verify iswalpha_l process success. Determine the number of letters in the unicode
 *                 code table, when the locale is en_US.UTF-8.
 * @tc.level     : Level 1
 */
void iswalpha_l_0100(void)
{
	locale_t m_locale = newlocale(LC_CTYPE_MASK, "en_US.UTF-8", NULL);
	int total = 0;
	for (int i = 0; i < SIZE; i++) {
		int ret = iswalpha_l(i, m_locale);
		if (ret) {
			total++;
		}
	}
	EXPECT_EQ("iswalpha_l_0100", total, COUNT);
}

/**
 * @tc.name      : iswalpha_l_0200
 * @tc.desc      : Verify iswalpha_l process success. Determine the number of letters in the unicode
 *                 code table, when the locale is zh_CN.
 * @tc.level     : Level 1
 */
 void iswalpha_l_0200(void)
 {
	 locale_t m_locale = newlocale(LC_CTYPE_MASK, "zh_CN", NULL);
	 int total = 0;
	 for (int i = 0; i < SIZE; i++) {
		 int ret = iswalpha_l(i, m_locale);
		 if (ret) {
			 total++;
		 }
	 }
	 EXPECT_EQ("iswalpha_l_0200", total, COUNT);
 }

int main(void)
{
	if (get_device_api_version_inner() >= DEVICE_VERSION_THRESHOLD) {
		return t_status;
	}
	iswalpha_l_0100();
	iswalpha_l_0200();
	return t_status;
}